import { defineStore } from 'pinia'
import { ref } from 'vue'
import wsHandle from '@/websocket/websocket.ts'
import { LoginType, WsRequestMsgType } from '@/enums'

enum LoginStatus {
  Init,
  Waiting,
  Success,
}

export const useLoginWsStorage = defineStore('wsLoginStorage', () => {
  //登录的二维码地址或者授权地址
  const authLoginUrl = ref<string>('')
  //登录状态
  const loginStatus = ref(LoginStatus.Init)

  //获取登录的授权码（可能是微信二维码或者第三方授权码）
  function getAuthLoginUrl(loginType: LoginType) {
    wsHandle.send({
      type: WsRequestMsgType.RequestLoginQrCode,
      data: {
        loginType: loginType,
      },
    })
  }

  //重置登录状态
  function resetLoginStatus() {
    loginStatus.value = LoginStatus.Init
    authLoginUrl.value = '';
  }

  return { authLoginUrl, loginStatus, getAuthLoginUrl,resetLoginStatus }
})
